package cn.vin.web;

import cn.vin.model.req.ReqLogin;
import cn.vin.properties.MyProperties2;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.context.properties.bind.BindResult;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

@RestController
@RequestMapping("/prop")
public class PropertiesController {
    private Logger log = LoggerFactory.getLogger(this.getClass());

    @Autowired
    private MyProperties2 myProperties2;

    @GetMapping(value = "/2",produces = "application/json")
    public MyProperties2 myProperties2(MyProperties2 prop) {
        log.info("=================================================================================================");
        log.info(myProperties2.toString());
        log.info("=================================================================================================");
        return myProperties2;
    }

    @PostMapping("/valid")
    public void valid(@Valid ReqLogin reqLogin, BindingResult bindResult) {
        if(bindResult.hasErrors()) {

        }
        System.out.println(reqLogin.getOpenid());
    }

    @PostMapping("/valid2")
    public void valid2(@RequestBody @Valid ReqLogin reqLogin, BindingResult bindResult) {
        if(bindResult.hasErrors()) {

        }
        System.out.println(reqLogin.getOpenid());
    }
}
